
////////////////////////////////////////////////////////////
//	File:		"SpinLock.h"
//	Author:		[AL] Anthony Lundquist
//	Created:	[AL] December 6, 2009
//	Purpose:	A Spin Lock for multithreading
////////////////////////////////////////////////////////////

#ifndef SPINLOCK_H_
#define SPINLOCK_H_

class SpinLock
{

public:

	/* Public Data Members */

protected:

	/* Protected Data Members */

private:

	/* Private Data Members */
	volatile bool	m_bIsLocked;

	/* Disabled Functions */

public:

	void DelayActivate();
	void DelayLock();

	////////////////////////////////////////////////////////////
	//	Function:	Activate
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Turns the SpinLock on and Locks the thread
	//				until Deactivate() is called
	////////////////////////////////////////////////////////////
	void Activate();

	////////////////////////////////////////////////////////////
	//	Function:	Deactivate
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Unlocks the Thread that called Activate()
	////////////////////////////////////////////////////////////
	void Deactivate();

	////////////////////////////////////////////////////////////
	//	Function:	Constructor
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Initializes the object.
	////////////////////////////////////////////////////////////
	SpinLock();

	////////////////////////////////////////////////////////////
	//	Function:	Accessors
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Returns a specific data member.
	//	Out:		The data member.
	////////////////////////////////////////////////////////////
	inline	bool	IsLocked()	{	return m_bIsLocked;	}

	////////////////////////////////////////////////////////////
	//	Function:	Mutators
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Sets a specific data member.
	//	In:			The new value.
	////////////////////////////////////////////////////////////

	////////////////////////////////////////////////////////////
	//	Function:	Destructor
	//	Created:	[AL] December 6, 2009
	//	Purpose:	Deallocates the object.
	////////////////////////////////////////////////////////////
	~SpinLock();

protected:

	/* Protected Functions */

private:

	/* Private Functions */
	inline	void	Lock()		{	m_bIsLocked=true;	}
	inline	void	Unlock()	{	m_bIsLocked=false;	}

};

#endif
